package com.example.hys.teamList;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.superyi.myteam.R;

import java.util.List;

public class TeamAdapter extends RecyclerView.Adapter<TeamAdapter.ViewHolder> {

    private List<TeamBean> mTeamList;

    //内部类，绑定控件
    static class ViewHolder extends RecyclerView.ViewHolder{

        TextView team_id;
        TextView competition;
        TextView cpt_category;
        TextView team_name;
        TextView team_leader;
        TextView mem_number;

        public ViewHolder(View view) {
            super(view);
            team_id = view.findViewById(R.id.team_id);
            competition = view.findViewById(R.id.competition);
            cpt_category = view.findViewById(R.id.cpt_category);
            team_name = view.findViewById(R.id.team_name);
            team_leader = view.findViewById(R.id.team_leader);
            mem_number = view.findViewById(R.id.mem_number);
        }
    }

    //构造方法，传入数据
    public TeamAdapter(List<TeamBean> teamList) {
        mTeamList = teamList;
    }

    @Override
    public ViewHolder onCreateViewHolder( ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.team_item_format,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder( ViewHolder holder, int position) {
        TeamBean teamBean = mTeamList.get(position);
        holder.team_id.setText(String.valueOf(teamBean.getTeam_id()));
        holder.competition.setText(teamBean.getCompetition());
        holder.cpt_category.setText(teamBean.getCpt_category());
        holder.team_name.setText(teamBean.getTeam_name());
        holder.team_leader.setText(teamBean.getTeam_leader());
        holder.mem_number.setText(String.valueOf(teamBean.getMem_number()));
    }

    @Override
    public int getItemCount() {
        return mTeamList.size();
    }
}
